#ifndef SYSYF_COMSUBEXPRELI_H
#define SYSYF_COMSUBEXPRELI_H

#include "Pass.h"
#include <map>
#include <set>
#include "Instruction.h"



/*****************************CommonSubExprElimination**************************************/
/***************************This class is based on SSA form*********************************/
/***************************you need to finish this class***********************************/
class ComSubExprEli : public Pass {
public:
    std::map<BasicBlock *, std::set<Instruction *>> e_gen_B;  
    std::map<BasicBlock *, std::set<Instruction *>> IN_B;  
    std::map<BasicBlock *, std::set<Instruction *>> OUT_B; 
    explicit ComSubExprEli(Module* module):Pass(module){}
    const std::string get_name() const override {return name;}
    void execute() override;
    static bool is_valid_expr(Instruction* inst);
    bool compare(Instruction *expr1, Instruction *expr2);
    void in_block();
    bool updatein(BasicBlock *bb);
    bool updateout(BasicBlock *bb);
    void between_block();
private:
    Function *func_;
    const std::string name = "ComSubExprEli";

};

#endif // SYSYF_COMSUBEXPRELI_H